/*
 * Copyright (C) 2014 Eduardo Pereira Montenegro <epereiramontenegro@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.bambole.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Eduardo Pereira Montenegro <epereiramontenegro@gmail.com>
 */
@Entity
@Table(name = "user")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
    @NamedQuery(name = "User.findEnabled", query = "SELECT u FROM User u WHERE u.enabled = true"),
    @NamedQuery(name = "User.findByEmailAddress", query = "SELECT u FROM User u WHERE u.emailAddress = :emailAddress"),
    @NamedQuery(name = "User.findEnabledByEmailAddress", query = "SELECT u FROM User u WHERE u.enabled = true AND u.emailAddress = :emailAddress")})
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "created")
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;
    @Basic(optional = false)
    @NotNull
    @Column(name = "updated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updated;
    @Basic(optional = false)
    @NotNull
    @Column(name = "enabled")
    private boolean enabled = true;
    @Basic(optional = false)
    @NotNull
    @Size(max = 64)
    @Column(name = "name")
    private String name;
    @Size(max = 128)
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Size(max = 64)
    @Column(name = "email_address")
    private String emailAddress;
    @Basic(optional = false)
    @NotNull
    @Size(max = 96)
    @Column(name = "password")
    private String password;
    @Size(max = 32)
    @Column(name = "locale")
    private String locale;
    @Size(max = 32)
    @Column(name = "theme")
    private String theme;
    @Column(name = "last_login")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLogin;
    @Column(name = "last_password_change")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastPasswordChange;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Person> personList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Person> personList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Status> statusList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Status> statusList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<ShipmentHeader> shipmentHeaderList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<ShipmentHeader> shipmentHeaderList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<User> userList;
    @JoinColumn(name = "updated_by", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User updatedBy;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<User> userList1;
    @JoinColumn(name = "created_by", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User createdBy;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<PaymentTerm> paymentTermList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<PaymentTerm> paymentTermList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Type> typeList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Type> typeList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Channel> channelList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Channel> channelList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Product> productList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Product> productList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<ShipmentItem> shipmentItemList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<ShipmentItem> shipmentItemList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Category> categoryList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Category> categoryList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<OrderHeader> orderHeaderList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<OrderHeader> orderHeaderList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<OrderItem> orderItemList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<OrderItem> orderItemList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Organization> organizationList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Organization> organizationList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Color> colorList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Color> colorList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Address> addressList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Address> addressList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Industry> industryList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Industry> industryList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<OrganizationNote> organizationNoteList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<OrganizationNote> organizationNoteList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "updatedBy")
    private List<Configuration> configurationList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "createdBy")
    private List<Configuration> configurationList1;

    public User() {
    }

    public User(Integer id) {
        this.id = id;
    }

    public User(Integer id, Date created, Date updated, boolean enabled, String name, String emailAddress, String password) {
        this.id = id;
        this.created = created;
        this.updated = updated;
        this.enabled = enabled;
        this.name = name;
        this.emailAddress = emailAddress;
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public Date getLastPasswordChange() {
        return lastPasswordChange;
    }

    public void setLastPasswordChange(Date lastPasswordChange) {
        this.lastPasswordChange = lastPasswordChange;
    }

    @XmlTransient
    public List<Person> getPersonList() {
        return personList;
    }

    public void setPersonList(List<Person> personList) {
        this.personList = personList;
    }

    @XmlTransient
    public List<Person> getPersonList1() {
        return personList1;
    }

    public void setPersonList1(List<Person> personList1) {
        this.personList1 = personList1;
    }

    @XmlTransient
    public List<Status> getStatusList() {
        return statusList;
    }

    public void setStatusList(List<Status> statusList) {
        this.statusList = statusList;
    }

    @XmlTransient
    public List<Status> getStatusList1() {
        return statusList1;
    }

    public void setStatusList1(List<Status> statusList1) {
        this.statusList1 = statusList1;
    }

    @XmlTransient
    public List<ShipmentHeader> getShipmentHeaderList() {
        return shipmentHeaderList;
    }

    public void setShipmentHeaderList(List<ShipmentHeader> shipmentHeaderList) {
        this.shipmentHeaderList = shipmentHeaderList;
    }

    @XmlTransient
    public List<ShipmentHeader> getShipmentHeaderList1() {
        return shipmentHeaderList1;
    }

    public void setShipmentHeaderList1(List<ShipmentHeader> shipmentHeaderList1) {
        this.shipmentHeaderList1 = shipmentHeaderList1;
    }

    @XmlTransient
    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    public User getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(User updatedBy) {
        this.updatedBy = updatedBy;
    }

    @XmlTransient
    public List<User> getUserList1() {
        return userList1;
    }

    public void setUserList1(List<User> userList1) {
        this.userList1 = userList1;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public String getNameWithDisabledFormatting() {
        return isEnabled() ? name : "~ " + name + " ~";
    }

    @XmlTransient
    public List<PaymentTerm> getPaymentTermList() {
        return paymentTermList;
    }

    public void setPaymentTermList(List<PaymentTerm> paymentTermList) {
        this.paymentTermList = paymentTermList;
    }

    @XmlTransient
    public List<PaymentTerm> getPaymentTermList1() {
        return paymentTermList1;
    }

    public void setPaymentTermList1(List<PaymentTerm> paymentTermList1) {
        this.paymentTermList1 = paymentTermList1;
    }

    @XmlTransient
    public List<Channel> getChannelList() {
        return channelList;
    }

    public void setChannelList(List<Channel> channelList) {
        this.channelList = channelList;
    }

    @XmlTransient
    public List<Channel> getChannelList1() {
        return channelList1;
    }

    public void setChannelList1(List<Channel> channelList1) {
        this.channelList1 = channelList1;
    }

    @XmlTransient
    public List<Type> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<Type> typeList) {
        this.typeList = typeList;
    }

    @XmlTransient
    public List<Type> getTypeList1() {
        return typeList1;
    }

    public void setTypeList1(List<Type> typeList1) {
        this.typeList1 = typeList1;
    }

    @XmlTransient
    public List<Product> getProductList() {
        return productList;
    }

    public void setProductList(List<Product> productList) {
        this.productList = productList;
    }

    @XmlTransient
    public List<Product> getProductList1() {
        return productList1;
    }

    public void setProductList1(List<Product> productList1) {
        this.productList1 = productList1;
    }

    @XmlTransient
    public List<ShipmentItem> getShipmentItemList() {
        return shipmentItemList;
    }

    public void setShipmentItemList(List<ShipmentItem> shipmentItemList) {
        this.shipmentItemList = shipmentItemList;
    }

    @XmlTransient
    public List<ShipmentItem> getShipmentItemList1() {
        return shipmentItemList1;
    }

    public void setShipmentItemList1(List<ShipmentItem> shipmentItemList1) {
        this.shipmentItemList1 = shipmentItemList1;
    }

    @XmlTransient
    public List<Category> getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(List<Category> categoryList) {
        this.categoryList = categoryList;
    }

    @XmlTransient
    public List<Category> getCategoryList1() {
        return categoryList1;
    }

    public void setCategoryList1(List<Category> categoryList1) {
        this.categoryList1 = categoryList1;
    }

    @XmlTransient
    public List<OrderHeader> getOrderHeaderList() {
        return orderHeaderList;
    }

    public void setOrderHeaderList(List<OrderHeader> orderHeaderList) {
        this.orderHeaderList = orderHeaderList;
    }

    @XmlTransient
    public List<OrderHeader> getOrderHeaderList1() {
        return orderHeaderList1;
    }

    public void setOrderHeaderList1(List<OrderHeader> orderHeaderList1) {
        this.orderHeaderList1 = orderHeaderList1;
    }

    @XmlTransient
    public List<OrderItem> getOrderItemList() {
        return orderItemList;
    }

    public void setOrderItemList(List<OrderItem> orderItemList) {
        this.orderItemList = orderItemList;
    }

    @XmlTransient
    public List<OrderItem> getOrderItemList1() {
        return orderItemList1;
    }

    public void setOrderItemList1(List<OrderItem> orderItemList1) {
        this.orderItemList1 = orderItemList1;
    }

    @XmlTransient
    public List<Organization> getOrganizationList() {
        return organizationList;
    }

    public void setOrganizationList(List<Organization> organizationList) {
        this.organizationList = organizationList;
    }

    @XmlTransient
    public List<Organization> getOrganizationList1() {
        return organizationList1;
    }

    public void setOrganizationList1(List<Organization> organizationList1) {
        this.organizationList1 = organizationList1;
    }

    @XmlTransient
    public List<Color> getColorList() {
        return colorList;
    }

    public void setColorList(List<Color> colorList) {
        this.colorList = colorList;
    }

    @XmlTransient
    public List<Color> getColorList1() {
        return colorList1;
    }

    public void setColorList1(List<Color> colorList1) {
        this.colorList1 = colorList1;
    }

    @XmlTransient
    public List<Address> getAddressList() {
        return addressList;
    }

    public void setAddressList(List<Address> addressList) {
        this.addressList = addressList;
    }

    @XmlTransient
    public List<Address> getAddressList1() {
        return addressList1;
    }

    public void setAddressList1(List<Address> addressList1) {
        this.addressList1 = addressList1;
    }

    @XmlTransient
    public List<Industry> getIndustryList() {
        return industryList;
    }

    public void setIndustryList(List<Industry> industryList) {
        this.industryList = industryList;
    }

    @XmlTransient
    public List<Industry> getIndustryList1() {
        return industryList1;
    }

    public void setIndustryList1(List<Industry> industryList1) {
        this.industryList1 = industryList1;
    }

    @XmlTransient
    public List<OrganizationNote> getOrganizationNoteList() {
        return organizationNoteList;
    }

    public void setOrganizationNoteList(List<OrganizationNote> organizationNoteList) {
        this.organizationNoteList = organizationNoteList;
    }

    @XmlTransient
    public List<OrganizationNote> getOrganizationNoteList1() {
        return organizationNoteList1;
    }

    public void setOrganizationNoteList1(List<OrganizationNote> organizationNoteList1) {
        this.organizationNoteList1 = organizationNoteList1;
    }

    @XmlTransient
    public List<Configuration> getConfigurationList() {
        return configurationList;
    }

    public void setConfigurationList(List<Configuration> configurationList) {
        this.configurationList = configurationList;
    }

    @XmlTransient
    public List<Configuration> getConfigurationList1() {
        return configurationList1;
    }

    public void setConfiguration1(List<Configuration> configurationList1) {
        this.configurationList1 = configurationList1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return "User[" + id + "]";
    }

}
